﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Practices.Unity;
using CP.Windows.Forms;
using MP3Ganizer.Common.Interfaces.DirectoryLoader;

namespace MP3Ganizer.Modules.DirectoryLoader.Views
{
    /// <summary>
    /// Interaction logic for DirectoryLoaderMainV.xaml
    /// </summary>
    public partial class DirectoryLoaderView : UserControl, IDirectoryLoaderView
    {
        #region Fields
        private readonly IUnityContainer _container;
        private ShellFolderBrowser _folderBrowserSource;
        private ShellFolderBrowser _folderBrowserDestination;
        private IDirectoryLoaderViewModel _model;
        #endregion

        /// <summary>
        /// Constructeur.
        /// </summary>
        /// <param name="container"></param>
        public DirectoryLoaderView(IUnityContainer container)
        {
            this._container = container;
            InitializeComponent();
            _folderBrowserSource = new ShellFolderBrowser();
            _folderBrowserSource.Initialized += new EventHandler(_folderBrowserSource_Initialized);
            _folderBrowserDestination = new ShellFolderBrowser();
            _folderBrowserDestination.Initialized += new EventHandler(_folderBrowserDestination_Initialized);
        }

        #region IDirectoryLoaderMainV Members

        /// <summary>
        /// Fonction pour associer un ViewModel à cette vue.
        /// </summary>
        /// <param name="model"></param>
        public void SetModel(IDirectoryLoaderViewModel model)
        {
            _model = model;
            this.DataContext = _model;
        }

        #endregion

        private void SourceDirButton_Click(object sender, RoutedEventArgs e)
        {
            _folderBrowserSource.Title = "Source";
            if (_folderBrowserSource.ShowDialog())
            {
                SourceDirTextBox.Text = _folderBrowserSource.FolderPath;
            }
        }

        void _folderBrowserSource_Initialized(object sender, EventArgs e)
        {
            _folderBrowserSource.SetSelection(SourceDirTextBox.Text);
        }


        private void DestinationDirButton_Click(object sender, RoutedEventArgs e)
        {
            _folderBrowserDestination.Title = "Destination";
            if (_folderBrowserDestination.ShowDialog())
                DestDirTextBox.Text = _folderBrowserDestination.FolderPath;
        }

        void _folderBrowserDestination_Initialized(object sender, EventArgs e)
        {
            _folderBrowserDestination.SetSelection(DestDirTextBox.Text);
        }
    }
}
